<?php
//pr($payments);
?>
<div class="payment index">
    <h2><?php echo __('Payment'); ?></h2>
    <table>
        <tr>
            <th><?php echo __('Plan') ?></th>
            <th><?php echo __('State') ?></th>
            <th><?php echo __('Date') ?></th>
            <th><?php echo __('Subscriber') ?></th>
            <th><?php echo __('Payment method') ?></th>
            <th><?php echo __('Amount') ?></th>
            <th>&nbsp;</th>
        </tr>
        <?php 
            
            foreach ($payments as $payment):
                $statusClass = '';
                $paddingLink = '';
                switch ($payment['Payment']['payment_status']) {
                    
                  case  PAYMENT_STATUS_COMPLETED:
                        $statusClass = 'complete-status';
                        break;
                  case PAYMENT_STATUS_INPROGRESS:
                        $statusClass = 'inprogress-status';
                        break;
                   case PAYMENT_STATUS_PENDING:
                       $statusClass = 'pending-status';
                       $paddingLink = $this->Form->postLink(__('Complete payment'), array('action' => 'updateStatus', $payment['Payment']['id'], 1, 'admin' => true), null, __('Are you sure you want to  complete this payment.')); 
                        break;
                }
            ?>
            <tr>
                <td><?php echo h($payment['SubscriptionTerm']['name']); ?>&nbsp;</td>
                <td><?php echo $this->Html->tag('span', $payment['Payment']['payment_status'], array('class' => $statusClass)); ?></td>
                <td><?php echo date('F d, Y h:i', strtotime($payment['Payment']['payment_date'])) ?>&nbsp;</td>
                <td><?php echo h($payment['User']['name']); ?>&nbsp;</td>
                <td><?php echo ($payment['Subscription']['payment_method']); ?>&nbsp;</td>
                <td>$<?php echo h($payment['Payment']['payment_gross']); ?>&nbsp;</td>

                <td class="actions"><?php 
                    echo $paddingLink;
                    echo $this->Html->link(__('Print'), array('action' => 'print', $payment['Subscription']['id'], 'admin' => true), array('target' => '_blank')); 
                    //echo $this->Html->link(__('Detail'), array('action' => 'view', $payment['Subscription']['id'], 'admin' => true)); 
                ?></td>
            </tr>
        <?php endforeach; ?>
    </table>
    <p>
        <?php
        echo $this->Paginator->counter(array(
            'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
        ));
        ?>	</p>

    <div class="paging">
        <?php
        echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
        echo $this->Paginator->numbers(array('separator' => ''));
        echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
        ?>
    </div>